-- ======================================================================
-- Hell Lua Bus
-- 
-- Copyright 2012-2013Hell-Prototypes
--
-- http://www.hellprototypes.com/
--
-- This is free software, licensed under the terms of the GNU General
-- Public License as published by the Free Software Foundation.
-- ======================================================================
hlb = require('libhlb')

function device_open()
	local ret = hlb.usb_open()
	if ret < 0 then
		print("Fail to open usb device")
		return false
	end
	
	return true
end

function device_close()
	local ret = hlb.usb_close()
	if ret < 0 then
		print("Fail to close usb device")
		return false
	end
	
	return true
end
-- -----------------------------------------------
port_mask = {[0]=0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000}

device_open()

ret = hlb.port_write(0)
if ret < 0 then
	print("io_init : hlb_port_write ret = ", ret)
	return false
end

ret = hlb.port_oe(0xff)
if ret < 0 then
	print("io_init : hlb_port_oe ret = ", ret)
	return false
end

for i=8, 12 do
	ret = hlb.port_write(port_mask[i])
	print("i = " .. i)
	if ret < 0 then
		print("io_init : hlb_port_write ret = ", ret)
		return false
	end
	io.write("\r\nAny key to close continue ...")
	io.read()
	print("")
end

device_close()
